package com.yn.xgame;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * CommonConfig
 * 通用服务器配置
 * Created by wangboo on 17/7/13.
 */
public class CommonConfig {


    private int id;
    private String innerIp;
    private int port;
    private String topic;
    private int maxUser;
    private String zkAddress;
    private String mqNameAddr;
    private String mqGroup;
    private String topicPrefix;
    protected Properties prop;
    protected Properties kafkaProp;
    private String redisIp;
    private int redisPort;

    public CommonConfig(String topicPrefix, String file) throws IOException {
        this.topicPrefix = topicPrefix;
        prop = new Properties();
        InputStream is = getClass().getClassLoader().getResourceAsStream(file);
        prop.load(is);
        is = getClass().getClassLoader().getResourceAsStream("kafka.cfg");
        kafkaProp = new Properties();
        kafkaProp.load(is);
        id = Integer.parseInt(prop.getProperty("id"));
        innerIp = prop.getProperty("innerIp");
        port = Integer.parseInt(prop.getProperty("port"));
        topic = topicPrefix + id;
        maxUser = Integer.parseInt(prop.getProperty("maxUser", "1000"));
        zkAddress = prop.getProperty("zkAddress");
        mqGroup = prop.getProperty("mqGroup", "yn");
        mqNameAddr = prop.getProperty("mqNameAddr");
        redisIp = prop.getProperty("redis.ip");
        redisPort = Integer.parseInt(prop.getProperty("redis.port", "6379"));
    }

    public int getId() {
        return id;
    }

    public String getInnerIp() {
        return innerIp;
    }

    public int getPort() {
        return port;
    }

    public String getTopic() {
        return topic;
    }

    public int getMaxUser() {
        return maxUser;
    }

    public String getZkAddress() {
        return zkAddress;
    }

    public String getMqNameAddr() {
        return mqNameAddr;
    }

    public String getMqGroup() {
        return mqGroup;
    }

    public Properties getKafkaProp() {
        return kafkaProp;
    }

    public String getRedisIp() {
        return redisIp;
    }

    public int getRedisPort() {
        return redisPort;
    }
}
